
package vistaprincipal;

import java.util.ArrayList;
import java.util.List;

public class Hipotesis {
    String exp [];
    String simb[];
    String atom;
    String imprefp;
    List<String> atomicas;
    List<String> caden;
      
    public Hipotesis buscador (List<String> hipot){
         String cadena=""; 
         Hipotesis I=crear();
         I.atomicas = new ArrayList();
         I.atom="";
         I.imprefp="";
         I.caden = new ArrayList();
         int m=65;
         
        for(int j=0;j<hipot.size();j++){
	       
               cadena=hipot.get(j);
               //1ra comparación
		cadena="& "+cadena+" @"; //pongo a & 
		for(int i=0;i<I.simb.length;i++)
		cadena=cadena.replaceAll(I.exp[i],I.simb[i]);
		//2da comparación o bien
		String aux2=cadena.replace(" o bien ","");
		if(aux2.length()<cadena.length())
		  {
			cadena=cadena.replaceFirst(" o bien ","");
			cadena=cadena.replace(" o bien "," @∨& ");
		  }
		//3da comparación o ambos
		aux2="";
		aux2=cadena.replace(" o ambos ","");
		if(aux2.length()<cadena.length())
		  {
			cadena=cadena.replaceFirst(" o ambos ","");
			cadena=cadena.replace(" o "," @∨& ");
		  }
		//4da comparación al menos
		aux2="";
		aux2=cadena.replace(" al menos ","");
		if(aux2.length()<cadena.length())
		  {
			cadena=cadena.replaceFirst(" al menos ","");
			cadena=cadena.replace(" o "," @∨& ");
		  }
		//5da comparación como minimo
				aux2="";
				aux2=cadena.replace(" como minimo ","");
				if(aux2.length()<cadena.length())
				  {
					cadena=cadena.replaceFirst(" como minimo ","");
					cadena=cadena.replace(" o "," @∨& ");
				  }
		//7ma comparación solo si entonces
				aux2="";
				aux2=cadena.replace(" solo si ","");
				if(aux2.length()<cadena.length())
				  {
					cadena=cadena.replaceFirst(" solo si ","");
					cadena=cadena.replace(" entonces "," @∨7& ");
				  }
		//6ta comparación si entonces
				aux2="";
				aux2=cadena.replace(" entonces ","");
				if(aux2.length()<cadena.length())
				  {
					cadena=cadena.replaceFirst(" si ","");
					cadena=cadena.replace(" entonces "," @→& ");
				  }				
		//8va comparación solo si entonces
				aux2="";
				aux2=cadena.replace(" si ","");
				if(aux2.length()<cadena.length())
				  {
					cadena=cadena.replaceFirst(" si "," @∨7& ");
					
				  }
                cadena=cadena.replaceAll(" o "," @∨& ");

		//System.out.println(cadena); 		
		cadena=cadena.replace("&@","");//quita los &@
		cadena=cadena.replace("& @","");//quita los &@
		//cadena=cadena.replace(" &@","");//quita los &@
		
		String aux="";
		String cadena2="";
		for (int i=0;i<cadena.length();i++) //separacion de las atomicas
		  {
			aux="";
			if(cadena.codePointAt(i)==38)
			 {
			  while(cadena.codePointAt(i)!=64)
			     { 
				   aux=aux+(char)cadena.codePointAt(i);
				   i++;
			     }
                          aux=aux.replace("&","");
                          String ato="";
                          int flag=0;
                          for(int k=0;k<I.atomicas.size();k++){
                              ato=I.atomicas.get(k).replaceAll(" ","");                              
                              if(ato.equals(aux.replaceAll(" ",""))){
                                  cadena2=cadena2+(char)(k+65);
                                  flag=1;
                                  break;
                              }
                          }
                          if(flag==0){  
                            I.atomicas.add(aux);
                            I.atom+=(char)m+": "+aux+"\n";
                            cadena2=cadena2+(char)m;
                            m++;  
                          }
                          
                          //I.atomicas.add(aux);
			  
			 }
                        else{
                            
                            cadena2=cadena2+(char)cadena.codePointAt(i);
                        
                        }
		  }
		if(j+1<hipot.size())
                    I.imprefp+="H"+j+": "+cadena2+"\n";
                else
                    I.imprefp+="C:"+cadena2+"\n";
		I.caden.add(cadena2);
		
                
        }
        return I;
}
	
	public static Hipotesis crear ()
	   {
		Hipotesis I=new Hipotesis();
		I.exp =new String [18];
		I.simb =new String [18];
		I.exp[0]=" es necesario y sufuciente para ";
		I.exp[1]=" es suficiente para ";
		I.exp[2]=" no es el caso que ";
		I.exp[3]=" no es cierto que ";
		I.exp[4]=" no ocurre que ";
		I.exp[5]=" es falso que ";
		I.exp[6]=" si y solo si ";
		I.exp[7]=" sin embargo ";
		I.exp[8]=" no obstante ";
		I.exp[9]=" a menos que ";
		I.exp[10]=" a pesar de ";
		I.exp[11]=" sólo si ";
		I.exp[12]=" aunque ";
		I.exp[13]=" pero ";
		I.exp[14]=" no ";
		I.exp[15]=" ni ";
		I.exp[16]=" y ";
		I.exp[17]=" es necesario para ";
		I.simb[0]=" @⇔& ";
		I.simb[1]=" @→& ";
		I.simb[2]=" @7& ";
		I.simb[3]=" @7& ";
		I.simb[4]=" @7& ";
		I.simb[5]=" @7& ";
		I.simb[6]=" @⇔& ";
		I.simb[7]=" @∧& ";
		I.simb[8]=" @∧& ";
		I.simb[9]=" @∨& ";
		I.simb[10]=" @∧& ";
		I.simb[11]=" @→& ";
		I.simb[12]=" @∧& ";
		I.simb[13]=" @∧& ";
		I.simb[14]=" @7& ";
		I.simb[15]=" @7& ";
		I.simb[16]=" @∧& ";
		I.simb[17]=" @∨7& ";
		return I;
	   }   
}
